package yun.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class ShufflePlaylist<E> extends SequencePlaylist<E> {
	Random random = random = new Random();

	ShufflePlaylist(int index, List<E> list) {
		super(index, list);
		shuffleList();
	}

	void shuffleList() {

		List<E> list = new ArrayList<E>(getList());
		List<E> shuffleList = new ArrayList<E>(list.size());

		//
		E currentItem = list.remove(getIndex());
		shuffleList.add(currentItem);

		//
		E nextItem;
		int randomIndex;
		while (list.size() > 0) {
			randomIndex = random.nextInt(list.size());
			nextItem = list.remove(randomIndex);
			shuffleList.add(nextItem);
		}
		setList(shuffleList);
		setIndex(0);
	}
}